<template>
	<view class="container" v-if="login">
		<view class="card-view" v-for="(item,index) in articleList" :key="index">
			<uni-card class="card" @click="navTo(item)" :padding="0" :margin="0" :cover="item.imgUrl[0]">
			</uni-card>
			<text>标题:{{item.title}}</text>
		</view>
	</view>
	<view v-else>
		请去我的界面登入
	</view>
</template>

<script>
	export default {
		data() {
			return {
				login: false,
				userInfo: "",
				articleList: [{
					imgUrl: [],
					itle: "",
					content: "",
				}],
			};
		},
		onShow: function() {
			let userInfo = uni.getStorageSync("userInfo");
			if (userInfo != null && userInfo != "") {
				this.userInfo = userInfo;
				this.login = true;
				let that = this;
				let data = {
					"author_id": that.userInfo.id
				};
				uni.request({
					url: "http://localhost:8090/article/getMyArticle",
					method: "POST",
					data: data,
					success(res) {
						let list1 = res.data.data;
						let list2 = [];
						for (let item of list1) {
							let str = item.pictures
							let Pictures_url_arr = str.split(">>>");
							let imgUrl = []
							for (let item of Pictures_url_arr.slice(0, -1)) {
								imgUrl.push("http://192.168.31.77:80/app/img/" + item)
							}
							list2.push({
								imgUrl: imgUrl,
								title: item.title,
								content: item.content,
							})
						}
						that.articleList = list2;
					}
				})
			} else {
				this.login = false;
			}
		},
		methods: {
			navTo(item) {
				uni.navigateTo({
					url: "/pages/other/myArticle",
					success: (res) => {
						res.eventChannel.emit("navTomyArticle", item)
					}
				})
			}
		},
	};
</script>

<style lang="scss" scoped>
	.container {
		display: flex;
		flex-direction: row;
		align-content: space-around;
		flex-wrap: wrap;
	}

	.card-view {
		width: 49%;

	}
</style>